import {defineConfig} from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        electron({
            main: {
                // Shortcut of `build.lib.entry`.
                entry: 'electron/main.ts',
            },
            preload: {
                // Shortcut of `build.rollupOptions.input`.
                // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
                input: path.join(__dirname, 'electron/preload.ts'),
            },
            // Ployfill the Electron and Node.js built-in modules for Renderer process.
            // See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer
            renderer: {},
        }),
        AutoImport({
            // 自动导入vue的相关函数
            imports: ['vue', 'vue-router', 'pinia'],
            resolvers: [
                ElementPlusResolver(),
                IconsResolver({
                    prefix: 'Icon',
                }),
            ],
            dts: path.resolve(__dirname, 'types/auto-imports.d.ts'),
            eslintrc: {
                enabled: true, // Default `false`
                filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
                globalsPropValue: true,
            },
        }),
        Components({
            resolvers: [ElementPlusResolver(),
                // 自动注册图标组件
                // 如此Element图标在使用的时候就不能用<Edit/>了
                // 要用<i-ep-edit />  即<i-ep-xxx />
                IconsResolver({
                    enabledCollections: ['ep'],
                }),],
            dts: path.resolve(__dirname, 'types/components.d.ts'),
        }),
        Icons({
            autoInstall: true,
        })
    ],

    resolve: {
        alias: [
            {
                find: '@',
                replacement: path.join(__dirname, "./src")
            }
        ]
    }
})

console.log(path.join(__dirname, "./src"), 'vite')